#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

void if_perror();
int main(){
	int pipefd[2];
	int ret=pipe(pipefd);
	char buf[128];
	if_perror(ret,"pipe");
	pid_t pid=fork();
	if_perror(pid,"fork");
	if(pid==0){
		close(pipefd[1]);
		ssize_t byte= read(pipefd[0],buf,sizeof(buf));
		if(byte>0){
			printf("%s",buf);
		}
		close(pipefd[0]);
		exit(0);
	}else {
		close(pipefd[0]);
		fgets(buf,sizeof(buf),stdin);
		ssize_t byte= write(pipefd[1],buf,sizeof(buf));
		if(byte==-1){
			perror("write");
		}
		close(pipefd[1]);	
	}
	return 0;
}
void if_perror(int ret,char* str){
	if(ret==-1){
		perror(str);
		exit(1);
	}
}
